<template>
	<view>
		<view class="my-card">
			<view class="title">
				<text>我的卡包</text>
				<text>({{cardList.length}})张</text>
			</view>
			<text class="bind" @click="toBind">已有会员卡，绑卡即用</text>
		</view>
		<view class="card-list">
			<view class="card" :style="{backgroundImage:`url(${item.picture})`}" v-for="item in cardList"
				:key="item.cardCode" @click="showPassword(item.cardCode)">
				<view class="card-id">
					<text>卡号: {{item.cardCode}}</text>
				</view>
				<view class="recharge-btn">
					立即充值
				</view>
				<text style="margin-top: 300rpx;">{{tiem.getMinRecharge}}</text>
			</view>
		</view>
		<view class="card-bottom">
			<u-button shape="circle" customStyle="width:calc(100% - 60rpx)" type="primary" @click="toOpen">开卡</u-button>
			<text>更多优惠，开卡即享</text>
		</view>
		<u-popup mode='center' :round='10' :show="inputPassword" closeOnClickOverlay>
			<view class="input-password">

				<u--form labelPosition="left" :model="cardPayParams" ref="uForm" labelWidth='auto' labelAlign='right'>
					<u-form-item label="密码：" borderBottom ref="item4">
						<u--input name="密码" password required placeholder="密码" v-model="cardPayParams.password" />
					</u-form-item>
				</u--form>
				<view style="width: 100%;display: flex;justify-content: center;">
					<u-button shape="circle" type="primary" @click="login">
						确定</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getCardList,
		getCardInfo,
		getMemberCard
	} from '../../common/http/api.js'
	export default {
		data() {
			return {
				cardList: [],
				inputPassword: false,
				cardPolicyList: [],
				cardInfo: {
					password: "",
					cardCode: ''
				}
			}
		},
		methods: {
			queryCardList() {
				getCardList(uni.getStorageSync("openId")).then(res => {
					const {
						code,
						data
					} = res
					if (code === "000") {
						const list = data
						this.cardPolicyList.map(policy => {
							list.map(item => {
								if (policy.policyId == item.policyId) {
									item.picture = policy.picture
								}
							})
						})
						this.cardList = list
					}
				})
			},
			getCardPolicy() {
				getMemberCard().then(res => {
					this.cardPolicyList = res.list
					this.queryCardList()
				})
			},
			showPassword(card) {
				this.inputPassword = true
				this.cardInfo.cardCode = card

			},
			login() {
				getCardInfo(this.cardInfo).then(res => {
					const {
						code,
						msg
					} = res
					if (code === "000") {
						uni.navigateTo({
							url: "../cardPage/cardPage?cardCode=" + this.cardInfo.cardCode + '&password=' +
								this.cardInfo.password
						})
					} else {
						uni.showToast({
							title: msg,
							icon: "none"
						})
					}
				})
			},
			change(e) {
				this.cardInfo.password = e.detail
			},
			toOpen() {
				uni.navigateTo({
					url: '../openCard/openCardList'
				})
			},
			toBind() {
				uni.navigateTo({
					url: "../bindCard/bindCard"
				})
			}
		},
		created() {
			this.getCardPolicy()
			uni.setNavigationBarTitle({
				title: this.$store.state.cinemaName
			})
		},
		onHide() {
			this.inputPassword = false
			this.cardInfo.password = ''
		}
	}
</script>

<style lang="scss">
	.my-card {
		display: flex;
		justify-content: space-between;
		padding: 30rpx;
		align-items: center;

		.title {
			font-size: 32rpx;

			text:last-child {
				font-size: 24rpx;
				color: #999;
				margin-left: 15rpx;
			}
		}

		.bind {
			font-size: 22rpx;
			color: royalblue;
			text-decoration: underline;
		}
	}

	.card {
		width: 90vw;
		margin: 15rpx auto 0 auto;
		padding: 20rpx;
		height: 310rpx;
		background-size: 100% 100%;
		border-radius: 15rpx;
		color: #fff;
		position: relative;

		.recharge-btn {
			position: absolute;
			bottom: 20rpx;
			right: 20rpx;
			font-size: 28rpx;
			color: #fff;
			background-color: #f0aa3d;
			border-radius: 30rpx;
			padding: 10rpx 20rpx;
		}

		.card-id {
			font-size: 32rpx;
		}

		.card-level {
			font-size: 28rpx;
			margin-top: 200rpx;
		}

		.card-amount {
			font-size: 28rpx;
		}
	}

	.card-bottom {
		position: fixed;
		bottom: 0;
		height: 170rpx;
		width: 100vw;
		background-color: #fff;
		box-shadow: 0px -10rpx 6px 0rpx #f0f0f5;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 15rpx;
		padding: 10rpx 30rpx 0 30rpx;
		box-sizing: border-box;

		text {
			font-size: 22rpx;
			color: #999;
			margin-top: 15rpx;
		}
	}

	.input-password {
		width: 80vw;
		padding: 30rpx;
	}
</style>